/*
 * Copyright 2016-present the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.pnoker.center.manager.api;

import io.github.pnoker.api.center.manager.RobIdRobNameApiGrpc;
import io.github.pnoker.api.center.manager.RobNameRequest;
import io.github.pnoker.api.center.manager.RobNameResponse;
import io.github.pnoker.center.manager.service.RobIdRobNameService;
import io.github.pnoker.common.model.RobIDRobName;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;

import javax.annotation.Resource;

/**
 * Device Api
 *
 * @author pnoker
 * @since 2022.1.0
 */
@Slf4j
@GrpcService
// public class DeviceApi extends DeviceApiGrpc.DeviceApiImplBase {
public class RobIdRobNameApi extends RobIdRobNameApiGrpc.RobIdRobNameApiImplBase {

    @Resource
    private RobIdRobNameService robIdRobNameService;

     @Override
    public void selectByRobId(RobNameRequest request, StreamObserver<RobNameResponse> robNameResponse) {
        System.out.println("*****************Api");

        RobNameResponse.Builder rBuilder = RobNameResponse.newBuilder();

        RobIDRobName robIDRobName = robIdRobNameService.selectByRobId(request.getRobid());
        System.out.println("++++++++++++++++++++Api" + robIDRobName);

        rBuilder.setRobname(robIDRobName.getRobname());
        robNameResponse.onNext((rBuilder.build()));
        robNameResponse.onCompleted();

    }

}
